package cn.springcloud.fix.resource.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;

/**
 * 替换掉 AbstractOAuth2SecurityExceptionHandler 的 exceptionTranslator，默认是 DefaultWebResponseExceptionTranslator
 */
@Slf4j
public class MyWebResponseExceptionTranslator implements WebResponseExceptionTranslator<String> {

    @Override
    public ResponseEntity<String> translate(Exception e) throws Exception {
        return new ResponseEntity<>("{" + e.getMessage() + "}", HttpStatus.METHOD_NOT_ALLOWED);
    }
}
